<!DOCTYPE html>
<html lang="en">
<head>
    {include file="_public/_head"/}
</head>
<body>
{include file="_public/_header"/}

<div class="am-cf admin-main">
    {include file="_public/_sidebar"/}
    <!-- content start -->
    <div class="admin-content" id="ajaxFrom">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf">
                    <strong class="am-text-primary am-text-lg">新闻编辑</strong> /
                    <small>News</small>
                </div>
            </div>
            <hr>
            <div class="am-tabs am-margin" data-am-tabs>
                <ul class="am-tabs-nav am-nav am-nav-tabs">
                    <li class="am-active"><a href="#tab1">基本信息</a></li>
                    <li><a href="#tab2">详细描述</a></li>
                </ul>

                <div class="am-tabs-bd">
                    <div class="am-tab-panel am-fade am-in am-active" id="tab1">
                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2 am-text-right">展示图片</div>
                            <div class="am-u-sm-8 am-u-md-10">
                                <div class="am-form-group">
                                    <input type="file"/>
                                    <input type="hidden" id="pic" name="pic" value="{$detail.pic}"/>
                                    <p class="am-form-help">请选择要上传的文件...</p>
                                </div>
                                <img class="am-img-circle am-img-thumbnail am-u-sm-4" src="{$detail.pic}" alt=""/>
                            </div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2 am-text-right">显示状态</div>
                            <div class="am-u-sm-8 am-u-md-10">
                                <div class="am-btn-group" data-am-button>
                                    {if condition="2 neq $detail['status']"}
                                    <label class="am-btn am-btn-default am-btn-xs am-active">
                                        <input type="radio" name="status" checked="checked" value="1"> 显示
                                    </label>
                                    <label class="am-btn am-btn-default am-btn-xs">
                                        <input type="radio" name="status" value="2"> 不显示
                                    </label>
                                    {else/}
                                    <label class="am-btn am-btn-default am-btn-xs">
                                        <input type="radio" name="status" value="1"> 显示
                                    </label>
                                    <label class="am-btn am-btn-default am-btn-xs am-active">
                                        <input type="radio" name="status" checked="checked" value="2"> 不显示
                                    </label>
                                    {/if}
                                </div>
                            </div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2 am-text-right">新闻类型</div>
                            <div class="am-u-sm-8 am-u-md-10">
                                <div class="am-btn-group" data-am-button>
                                    {volist name="$newsType" id="vo"}
                                    {if condition="$vo['id'] eq $detail['type']"}
                                    <label class="am-btn am-btn-default am-btn-xs am-active">
                                        <input type="radio" name="type" value="{$vo.id}" checked="checked">
                                        {$vo.type_name}
                                    </label>
                                    {else/}
                                    <label class="am-btn am-btn-default am-btn-xs">
                                        <input type="radio" name="type" value="{$vo.id}"> {$vo.type_name}
                                    </label>
                                    {/if}
                                    {/volist}
                                </div>
                            </div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                文章标题
                            </div>
                            <div class="am-u-sm-4 am-u-md-4">
                                <input type="text" value="{$detail.title}" name="title">
                            </div>
                            <div class="am-hide-sm-only am-u-md-6">*必填，不可重复</div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                文章作者
                            </div>
                            <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                                <input type="text" value="{$detail.author}" name="author">
                            </div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                信息来源
                            </div>
                            <div class="am-u-sm-8 am-u-md-4">
                                <input type="text" value="{$detail.url}" name="url">
                            </div>
                            <div class="am-hide-sm-only am-u-md-6">选填</div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                内容摘要
                            </div>
                            <div class="am-u-sm-8 am-u-md-4">
                                <input type="text" value="{$detail.description}" name="description">
                            </div>
                            <div class="am-u-sm-12 am-u-md-6">不填写则自动截取内容前255字符</div>
                        </div>
                    </div>

                    <div class="am-tab-panel am-fade" id="tab2">
                        <div class="am-g am-margin-top-sm">
                            <div class="am-u-sm-12 am-u-md-2 am-text-right admin-form-text">
                                内容描述
                            </div>
                            <div class="am-u-sm-12 am-u-md-10">
                                <textarea id="editor" type="text/plain" style="width:1024px;height:500px;" name="content">
                                    {$detail.content}
                                </textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="am-margin">
                <button type="button" class="am-btn am-btn am-btn-danger js-modal-toggle am-btn-xs" id="ajaxSubmit">提交保存</button>
                <button type="button" class="am-btn am-btn-primary am-btn-xs" id="ajaxCancel">放弃保存</button>
            </div>
        </div>
    </div>
    <!-- content end -->
</div>
{include file="_public/_footer"/}
<script src="{$webConfig.static_url}/ueditor/ueditor.config.js"></script>
<script src="{$webConfig.static_url}/ueditor/ueditor.all.min.js"></script>
<script src="{$webConfig.static_url}/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    $(function () {
        $('#ajaxFrom').on('click', '#ajaxSubmit', function () {
            $.ajax({
                type: 'POST',
                url: "./detail",
                data: {
                    id: '{$detail.id}',
                    pic: $('input[name="pic"]').val(),
                    status: $('input[name="status"]:checked').val(),
                    type: $('input[name="type"]:checked').val(),
                    title: $('input[name="title"]').val(),
                    author: $('input[name="author"]').val(),
                    url: $('input[name="url"]').val(),
                    description: $('input[name="description"]').val(),
                    content: UE.getEditor('editor').getContent()
                },
                async: true,
                dataType: 'json',
                beforeSend: function () {
                    $('#ajaxSubmit').html('提交中...');
                },
                success: function (data) {
                    $('#ajaxSubmit').html('提交保存');
                    alertShow(data.message);
                    if('SUCCESS' == data.message) history.go(-1)
                },
                error: function () {
                    alertShow('保存失败');
                }
            });
        });
    })
</script>
<!-- content end -->
</body>
</html>